﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace XFPPT.NET
{
    /// <summary>
    /// 
    /// </summary>
    public static class CommonHelper
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public static string DecodeJson(string json)
        {
            string DecodeJson = string.Empty;
            try
            {
                using (JsonDocument document = JsonDocument.Parse(json))
                {
                    DecodeJson = JsonSerializer.Serialize(document.RootElement, new JsonSerializerOptions { Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping });
                }
            }
            catch (Exception)
            {
                DecodeJson = json;
                //throw;
            }
            if (string.IsNullOrWhiteSpace(DecodeJson))
            {
                DecodeJson = json;
            }
            return DecodeJson;
        }
    }
}
